package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.dto.AdComment;
import com.heima.model.comment.dtos.CommentPageQueryDTO;
import com.heima.model.review.CommentRepaySaveDto;
import com.heima.model.wemedia.dto.ArticleCommentStatusDto;
import com.heima.model.wemedia.dto.CommentManagementQueryDTO;
import com.heima.wemedia.service.WmCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WmCommentController {
    @Autowired
    private WmCommentService commentService;

    /**
     * 根据评论id删除评论
     *
     * @param commentId
     * @return
     */
    @DeleteMapping("/api/v1/comment/manage/del_comment/{commentId}")
    public ResponseResult delComment(@PathVariable("commentId") Long commentId) {
        commentService.delComment(commentId);
        return ResponseResult.ok();
    }

    /*
     * 根据回复id删除回复
     * @param replyId
     * @return
     */
    @DeleteMapping("/api/v1/comment/manage/del_comment_repay/{commentRepayId}")
    public ResponseResult delCommentRepay(@PathVariable("commentRepayId") Long replyId) {
        commentService.delCommentRepay(replyId);
        return ResponseResult.ok();
    }

    /**
     * 评论管理查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/manage/find_news_comments")
    public PageResult findNewsComments(@RequestBody CommentManagementQueryDTO dto) {
        return commentService.findNewsComments(dto);
    }


    /**
     * 评论和回复查询所有
     *
     * @param dto
     * @return
     */
    @PostMapping(" /api/v1/comment/manage/list")
    public ResponseResult manageList(@RequestBody CommentPageQueryDTO dto) {
        return ResponseResult.ok(commentService.getPage(dto));
    }

    /**
     * 作者回复评论
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/manage/comment_repay")
    public ResponseResult commentRepay(@RequestBody CommentRepaySaveDto dto) {
        return commentService.commentRepay(dto);
    }

    /**
     * 打开或关闭评论
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/manage/update_comment_status")
    public ResponseResult updateCommentStatus(@RequestBody ArticleCommentStatusDto dto) {
        commentService.updateCommentStatus(dto);
        return ResponseResult.ok();
    }
}
